Repository navigation
Conversation
- enforce a Content-Security-Policy and baseline security headers - gzip console JSON and /v1/models while leaving SSE and chat streams alone - rate-limit repeated invalid API keys per client and return 429 with Retry-After - enlarge the request-log queue, bound the pre-drop wait, and expose drop counters in /health
2582085 to
1f4f915
Compare
|
看过了,可以合,等这轮 CI。
没有动发布源、版本号或路由行为。CI 绿了我就合。 |
caigee-cmd
left a comment
There was a problem hiding this comment.
Direction is right: CSP, skipping gzip on /api/events and /api/chat, raising the log queue from 256 to 4096, waiting 25ms, and draining accepted writes on close are all good. CI is green. Two things to fix before merge.
Auth limiter keys on the raw peer address. clientIP uses r.RemoteAddr and never reads X-Forwarded-For / X-Real-Ip. Behind the reverse proxy this repo is deployed with, every client is one IP. Ten bad keys in a minute — including ten different people, or one shared NAT — 429s the whole console for a minute, and a later successful key from anyone on that address clears the counter via success(). Either document that this only works when the process is reached directly, or key the bucket on the forwarded client (only from a trusted proxy hop) plus a short hash of the presented secret so one scanner cannot lock everyone else out.
withJSONCompression swallows http.Flusher until the first write. Flush commits with allowCompress=false, which is correct, but only if the handler type-asserts http.Flusher on the wrapper. jsonResponseWriter.Flush exists, so SSE that asserts against the wrapper is fine; an assertion against the inner writer fails and the 15s comment heartbeat in #603 would buffer. Worth a test that an /api/* handler which is not in the skip list can still flush, or keep the skip list explicit for every streaming route. /api/accounts/.../login is plain JSON today, so this is not a Hijacker break.
/health exposing log_dropped and log_queue is what we want. No change requested on the CSP itself.
需要改什么CSP、gzip 跳过 1. 鉴权失败桶不能只用连接对端地址
addr := strings.TrimSpace(r.RemoteAddr)
if host, _, err := net.SplitHostPort(addr); err == nil {
return host
}桶的 key 就是这个字符串。 这个进程的部署方式是容器加反代(
请改成下面这个桶,而不是“读一下 X-Forwarded-For 就拿最左边”:
测试要补的不是现有那组“10 次后 429、成功后清零”。现有测试用的是直接
2. gzip 包装器把
|
Problem
The console and gateway currently answer every invalid key with a SQLite-backed lookup, send large JSON responses uncompressed, and silently drop request-log writes when the single SQLite writer falls behind. The rendered console also has no Content-Security-Policy.
Change
internal/server/authlimit.go: per-client in-memory limiter for invalid API keys. Ten failures in a minute block that client for a minute with429andRetry-After; a successful auth clears the counter, and requests that present no credentials do not consume the scan budget.internal/server/compress.go: gzip JSON for console/api/*(except/api/eventsand/api/chat) and/v1/models. SSE, chat streams, HEAD, andgzip;q=0clients are untouched.internal/server/middleware.go: enforce a tested Content-Security-Policy plus baselinenosniff/ frame / referrer / permissions headers on every response.internal/logs/recorder.go: raise the request-log queue from 256 to 4096, wait 25ms before dropping, log drops at most once per 30s, drain accepted writes on close instead of closing the channel under an active enqueue./healthexposeslog_droppedandlog_queue.This branch is based on
upstream/main; it does not change release identities, version numbers, or fork-specific defaults.Validation
go test ./...go vet ./...python scripts/release-notes.py self-testpython scripts/release-notes.py validategit diff --checkq=0/ no header commit on panic, queue grace and close drain, CSP and health counters.All six CI jobs (go, windows-host, worker, frontend, container, secrets) are green on the current head. Ready for review.